package com.jz.community.moduleshopping.timeLimit.presenter;

import com.jz.community.basecomm.bean.BaseResponseInfo;
import com.jz.community.basecomm.mvp.BaseLifeCyclePresent;
import com.jz.community.basecomm.net.rxandroid.OnLoadListener;
import com.jz.community.moduleshopping.timeLimit.bean.LimitGoodsBean;
import com.jz.community.moduleshopping.timeLimit.bean.LimitTimeBean;
import com.jz.community.moduleshopping.timeLimit.model.TimeLimitModel;
import com.jz.community.moduleshopping.timeLimit.model.TimeLimitModelImp;
import com.jz.community.moduleshopping.timeLimit.ui.TimeLimitView;

public class TimeLimitPresenter extends BaseLifeCyclePresent<TimeLimitView.View> implements TimeLimitView.Presenter {

    private TimeLimitView.View view;
    private TimeLimitModel timeLimitModel;

    public TimeLimitPresenter(TimeLimitView.View view) {
        this.view = view;
        this.timeLimitModel = new TimeLimitModelImp(view.getContext());

    }

    @Override
    public void initTimeData(String cityId, int page, int size) {
        timeLimitModel.initTimeData(cityId, page, size, new OnLoadListener<LimitTimeBean>() {
            @Override
            public void onSuccess(LimitTimeBean limitTimeBean) {
                view.setTimeData(limitTimeBean);
            }

            @Override
            public void onFail(String msg, int code) {
                view.showError(msg);

            }
        });
    }

    @Override
    public void initGoodsData(String cityId, String startTime, String endTime, int page, int size) {
        timeLimitModel.initGoodsData(cityId, startTime, endTime, page, size, new OnLoadListener<LimitGoodsBean>() {
            @Override
            public void onSuccess(LimitGoodsBean limitGoodsBean) {
                view.setGoodsData(limitGoodsBean, startTime, endTime);
            }

            @Override
            public void onFail(String msg, int code) {
                view.showError(msg);

            }
        });

    }

    @Override
    public void sendTips(long gid, String startTime) {
        timeLimitModel.sendTips(gid, startTime, new OnLoadListener<BaseResponseInfo>() {
            @Override
            public void onSuccess(BaseResponseInfo baseResponseInfo) {
                view.sendTipsSuccess(baseResponseInfo);
            }

            @Override
            public void onFail(String msg, int code) {
                view.sendTipsError(msg);
            }
        });
    }
}
